/**
 * 催收记录
 */
//初始化表格
var initGrid = function(){
	$('#resultTable').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 10, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[1, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sScrollX": "100%",
		"sScrollXInner": 1695,
	    "sAjaxSource":"sys/LoanCollection/list",
        "fnServerData":retrieveData,  //自定义数据获取函数
		"aoColumns" : [{
			"mDataProp" : "",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		      var id = row.id;
		      var parseStr = '<a href="javascript:editWeb('+id+');" class="tablelink" >查看</a>&nbsp;';
		      return parseStr;
		    }
			
		},{
			"mDataProp" : "linkName",
			"sTitle" : "联系人",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "linkRelation",
			"sTitle" : "关系",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "linkTel",
			"sTitle" : "联系电话",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "collectionMode",
			"sTitle" : "催收方式",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		      return top.SYS_BASE_DATA['Loan_Collection_Mode_Code'][data] || '异常';
			}
		}, {
			"mDataProp" : "collectionUserName",
			"sTitle" : "催收人",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "collectionDate",
			"sTitle" : "催收日期",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var value = '';
				if(_is_empty(data)){
					value = '';
				}else{
					value = new Date(data).format('yyyy-MM-dd');
				}
				
	            return value;
		     }
		}, {
			"mDataProp" : "commitmentAmount",
			"sTitle" : "承诺还款金额",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "commitmentDate",
			"sTitle" : "承诺还款日期",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var value = '';
				if(_is_empty(data)){
					value = '';
				}else{
					value = new Date(data).format('yyyy-MM-dd');
				}
				
	            return value;
		     }
		}, {
			"mDataProp" : "collectionRemark",
			"sTitle" : "催收内容",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源
        }
        
	});
	
};

//自定义数据获取函数
var retrieveData = function ( sSource, aoData, fnCallback ) {
		var array = $("#_form_search_default").serializeArray();
		array.push({name:'loanId',value:_param_id});
		aoData = parent._set_query_conditions(aoData,array);
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
};

//查看催收信息
var editWeb = function(id){
	var aData = $('#resultTable').dataTable().fnGetData();
	$.each(aData,function(index,node){
		if(node.id==id){
			_set_default_lable_text('',true,node);
			return;
		}
	});
};

//初始化
$(function(){
	initGrid();
});